package com.xiaojianhx.demo.algorithm.sort;

/**
 * 选择排序
 * 
 * @author xiaojianhx
 * @version V1.0.0 $ 2021-04-18 23:47:23 init ---- xiaojianhx
 */
public class Algorithm_Sort_03_SelectionSort {

    public static void sort(int[] a) {

        for (var i = 0; i < a.length - 1; i++) {

            var m = i;

            for (var j = i + 1; j < a.length; j++) {
                if (a[j] < a[m]) {
                    m = j;
                }
            }

            if (i != m) {
                var t = a[i];
                a[i] = a[m];
                a[m] = t;
            }
        }
    }
}